﻿namespace GasFee
{
    public class GasPriceConventer
    {
        public double RegularPerGallonPrice { get; set; }
        public double LowerstSharpPerLitePrice { get; set; }
        public double MilePerGallon { get; set; }
        public double LiterPerOneHundradKilometer { get; set; }
        public double RmbOneUsd { get; set; }
        public double GetLiterPerOneHundradKilometerFromMpg(double mpg)
        {
            MilePerGallon = mpg;
            double kilometerPerGallon = MilePerGallon/MilePerOneKilometer;
            double kilometerPerLiter = kilometerPerGallon/GallonPerOneLiter;
            LiterPerOneHundradKilometer = 100F/kilometerPerLiter;
            return LiterPerOneHundradKilometer;
        }

        public double GetMpgFromLiterPerOneHundradKilometer(double literPerHundradKilometer)
        {
            LiterPerOneHundradKilometer = literPerHundradKilometer;
            double kilometerPerLiter = 100F/LiterPerOneHundradKilometer;
            double kilometerPerGallon = kilometerPerLiter*GallonPerOneLiter;
            MilePerGallon = kilometerPerGallon*MilePerOneKilometer;
            return MilePerGallon;
        }

        public double GetBeijingPriceFromUsaPrice(double regularPerGallonPrice)
        {
            RmbOneUsd = 6.3F;
            RegularPerGallonPrice = regularPerGallonPrice;
            double regularPerGallonRmb = RegularPerGallonPrice*RmbOneUsd;
            LowerstSharpPerLitePrice = regularPerGallonRmb/GallonPerOneLiter;
            return LowerstSharpPerLitePrice;
        }

        public double GetUsaPriceFromBeijingPrice(double beijingPrice)
        {
            RmbOneUsd = 6.3F;
            LowerstSharpPerLitePrice = beijingPrice;
            double lowerstSharpPerLiterUsd = LowerstSharpPerLitePrice/RmbOneUsd;
            RegularPerGallonPrice = lowerstSharpPerLiterUsd*GallonPerOneLiter;
            return RegularPerGallonPrice;
        }

        private const double MilePerOneKilometer = 0.621371192237334;
        private const double GallonPerOneLiter = 3.785411784;
    }
}
